#ifndef __MUTEX_H__
#define __MUTEX_H__

#include <pthread.h>

class Mutex {
  private:
    pthread_mutex_t mutex;
    pthread_cond_t cond;

    Mutex(const Mutex &m) { }

  public:
    Mutex() {
        pthread_mutex_init(&mutex, 0);
        pthread_cond_init(&cond, NULL);
    }

    ~Mutex() {
        pthread_mutex_destroy(&mutex);
        pthread_cond_destroy(&cond);
    }

    void esperar() {
        pthread_cond_wait(&cond, &mutex);
    }

    void avisar() {
        pthread_cond_signal(&cond);
    }

    void lock() {
        pthread_mutex_lock(&mutex);
    }

    void unlock() {
        pthread_mutex_unlock(&mutex);
    }
};

#endif
